using UnityEngine;
using QFramework;

namespace survivor
{
	public partial class Player : ViewController
	{
		public float moveSpeed = 5.0f;

		public static Player ins;

        private void Awake()
        {
            ins = this;
        }

        private void OnDestroy()
        {
            ins = null;
        }

        void Start()
		{
			// Code Here
			HurBox.OnTriggerEnter2DEvent(collider2D =>
			{
				if (collider2D.CompareTag("Enemy"))
				{
                    Global.HP.Value --;
                    if(Global.HP.Value <= 0){
                        Global.HP.Value = 0;
                        UIKit.OpenPanel<UIGameOverPanel>();

                        this.DestroyGameObjGracefully();
                    }
                }
				
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
		}

        private void Update()
        {
			var horizontal = Input.GetAxis("Horizontal");
			var vertical = Input.GetAxis("Vertical");
			var direction = new Vector2 (horizontal, vertical).normalized;

			SelfRigidbody2D.velocity = direction * moveSpeed;
        }
    }
}
